/*
    Copyright © 2019 by The qTox Project Contributors

    This file is part of qTox, a Qt-based graphical interface for Tox.

    qTox is libre software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    qTox is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with qTox.  If not, see <http://www.gnu.org/licenses/>.
*/

#pragma once
#include "../util/sha256.h"
#include "toxfilepause.h"
#include <vector>
#include <string>
#include <memory>
#include <fstream>

struct ToxFile
{
    // Note do not change values, these are directly inserted into the DB in their
    // current form, changing order would mess up database state!
    enum FileStatus
    {
        INITIALIZING = 0,
        PAUSED = 1,
        TRANSMITTING = 2,
        BROKEN = 3,
        CANCELED = 4,
        FINISHED = 5,
    };

    // Note do not change values, these are directly inserted into the DB in their
    // current form (can add fields though as db representation is an int)
    enum FileDirection : bool
    {
        SENDING = 0,
        RECEIVING = 1,
    };

    ToxFile() = default;
    ToxFile(uint32_t FileNum, uint32_t FriendId, std::string FileName, std::string filePath,
            FileDirection Direction);

    bool operator==(const ToxFile& other) const;
    bool operator!=(const ToxFile& other) const;

    void setFilePath(std::string path);
    bool open(bool write);

    uint8_t fileKind;
    uint32_t fileNum;
    uint32_t friendId;
    std::string fileName;
    std::string filePath;
    std::shared_ptr<std::fstream > file;
    uint64_t bytesSent;
    uint64_t filesize;
    FileStatus status;
    FileDirection direction;
    std::vector<unsigned char> avatarData;
    std::vector<unsigned char> resumeFileId;
    std::shared_ptr<SHA256> hashGenerator = std::make_shared<SHA256>();
    ToxFilePause pauseStatus;
};
